/**
 * 
 */
package com.chengyu.eyc.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import com.chengyu.eyc.interceptor.EycHandshakeInterceptor;
import com.chengyu.eyc.socket.EycWebSocketHandler;

/**
 * @author kevin
 *
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig  implements WebSocketConfigurer{

    @Autowired
    EycWebSocketHandler eycWebSocketHandler;
    /**
     * 通过继承 {@link org.springframework.web.socket.handler.AbstractWebSocketHandler} 的示例
     */
   
    @Bean
    public EycHandshakeInterceptor eycHandshakeInterceptor(){
        return new EycHandshakeInterceptor();
    }

    /**
     * @see org.springframework.web.socket.config.annotation.WebSocketConfigurer#registerWebSocketHandlers(org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry)
     */
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(eycWebSocketHandler, "/eycMessage").addInterceptors(eycHandshakeInterceptor()).setAllowedOrigins("*");
        registry.addHandler(eycWebSocketHandler, "/eycMessage_SockJS").addInterceptors(eycHandshakeInterceptor()).setAllowedOrigins("*").withSockJS();
    }

   
}
